package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.DVoucher;
import com.ruoyi.system.service.IDVoucherService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 优惠卷管理Controller
 *
 * @author tjm
 * @date 2025-04-03
 */
@RestController
@RequestMapping("/voucher")
public class DVoucherController extends BaseController
{
    @Autowired
    private IDVoucherService dVoucherService;

    /**
     * 查询优惠卷管理列表
     */
    @RequiresPermissions("system:voucher:list")
    @GetMapping("/list")
    public TableDataInfo list(DVoucher dVoucher)
    {
        startPage();
        List<DVoucher> list = dVoucherService.selectDVoucherList(dVoucher);
        return getDataTable(list);
    }

    /**
     * 导出优惠卷管理列表
     */
    @RequiresPermissions("system:voucher:export")
    @Log(title = "优惠卷管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DVoucher dVoucher)
    {
        List<DVoucher> list = dVoucherService.selectDVoucherList(dVoucher);
        ExcelUtil<DVoucher> util = new ExcelUtil<DVoucher>(DVoucher.class);
        util.exportExcel(response, list, "优惠卷管理数据");
    }

    /**
     * 获取优惠卷管理详细信息
     */
    @RequiresPermissions("system:voucher:query")
    @GetMapping(value = "/{vid}")
    public AjaxResult getInfo(@PathVariable("vid") Long vid)
    {
        return success(dVoucherService.selectDVoucherByVid(vid));
    }

    /**
     * 新增优惠卷管理
     */
    @RequiresPermissions("system:voucher:add")
    @Log(title = "优惠卷管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DVoucher dVoucher)
    {
        return toAjax(dVoucherService.insertDVoucher(dVoucher));
    }

    /**
     * 修改优惠卷管理
     */
    @RequiresPermissions("system:voucher:edit")
    @Log(title = "优惠卷管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DVoucher dVoucher)
    {
        return toAjax(dVoucherService.updateDVoucher(dVoucher));
    }

    /**
     * 删除优惠卷管理
     */
    @RequiresPermissions("system:voucher:remove")
    @Log(title = "优惠卷管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{vids}")
    public AjaxResult remove(@PathVariable Long[] vids)
    {
        return toAjax(dVoucherService.deleteDVoucherByVids(vids));
    }


    /**
     * 查询所有的优惠卷名称
     * */
//    @RequiresPermissions("system:voucher:lista")
    @GetMapping("/lista")
    public AjaxResult listName(){
        return success(dVoucherService.selectDVoucherNameList());
    }




}
